<?php
namespace TennisTournament\Model;

use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
class Player {

    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     * @var integer
     */
    protected $id;

    /**
     * @ORM\Column
     * @var string
     */
    protected $name;

    /**
     * @ORM\Column(name="job_position", nullable=true)
     * @var string
     */
    protected $jobPosition;

    /**
     * @ORM\Column(name="path_to_picture", nullable=true)
     * @var string
     */
    protected $pathToPicture;

    /**
     * @ORM\Column(name="number_winners", nullable=true, type="smallint")
     * @var int
     */
    protected $numberWinners;

    /**
     * @ORM\Column(name="number_losses", nullable=true, type="smallint")
     * @var int
     */
    protected $numberLosses;

    /**
     * @ORM\Column(name="madePoints", nullable=true )
     * @var int
     */
    protected $madePoints;

    /**
     * @ORM\Column(name="obtainedPoints", nullable=true )
     * @var int
     */
    protected $obtainedPoints;

    /**
     * @ORM\OneToOne(targetEntity="GroupStats", mappedBy="player")
     * @var GroupStats
     */
    protected $groupStats;

    public function __construct($data = array()) {
        if (count($data) > 0) {
            return $this->exchangeArray($data);
        }
    }

    /**
     * @param  $groupStats \TennisTournament\Model\GroupStats
     */
    public function setGroupStats($groupStats) {
        $this->groupStats = $groupStats;
    }

    /**
     * @return \TennisTournament\Model\GroupStats
     */
    public function getGroupStats() {
        return $this->groupStats;
    }

    /**
     * @param int $id
     */
    public function setId($id) {
        $this->id = $id;
    }

    /**
     * @return int
     */
    public function getId() {
        return $this->id;
    }

    /**
     * @param string $jobPosition
     */
    public function setJobPosition($jobPosition) {
        $this->jobPosition = $jobPosition;
    }

    /**
     * @return string
     */
    public function getJobPosition() {
        return $this->jobPosition;
    }

    /**
     * @param string $name
     */
    public function setName($name) {
        $this->name = $name;
    }

    /**
     * @return string
     */
    public function getName() {
        return $this->name;
    }

    /**
     * @param string $pathToPicture
     */
    public function setPathToPicture($pathToPicture) {
        $this->pathToPicture = $pathToPicture;
    }

    /**
     * @return string
     */
    public function getPathToPicture() {
        return $this->pathToPicture;
    }

    /**
     * @param int $madePoints
     */
    public function setMadePoints($madePoints)
    {
        $this->madePoints = $madePoints;
    }

    /**
     * @return int
     */
    public function getMadePoints()
    {
        return $this->madePoints;
    }

    /**
     * @param int $obtainedPoints
     */
    public function setObtainedPoints($obtainedPoints)
    {
        $this->obtainedPoints = $obtainedPoints;
    }

    /**
     * @return int
     */
    public function getObtainedPoints()
    {
        return $this->obtainedPoints;
    }

    /**
     * @param int $numberLosses
     */
    public function setNumberLosses($numberLosses) {
        $this->numberLosses = $numberLosses;
    }

    /**
     * @return int
     */
    public function getNumberLosses() {
        return $this->numberLosses;
    }

    /**
     * @param int $numberWinners
     */
    public function setNumberWinners($numberWinners) {
        $this->numberWinners = $numberWinners;
    }

    /**
     * @return int
     */
    public function getNumberWinners() {
        return $this->numberWinners;
    }

    /**
     * Convert a Player into a associative array
     * @return array
     */
    public function toArray() {
        return array(
            'id'                =>  $this->id,
            'name'              =>  $this->name,
            'jobPosition'       =>  $this->jobPosition,
            'pathToPicture'     =>  $this->pathToPicture,
            'numberWinners'     =>  $this->numberWinners,
            'numberLosses'      =>  $this->numberLosses,
            'madePoints'        =>  $this->madePoints,
            'obtainedPoints'    =>  $this->obtainedPoints
        );
    }

    /**
     * Create a {@link Player} object as populate the values
     * parsed from $data array
     * @param array $data
     * @return Player
     */
    public function exchangeArray($data = array()) {

        if (isset($data['id']) && ($this->id != $data['id'])) {
            $this->id = $data['id'];
        }

        if (isset($data['name']) && ($this->name != $data['name'])) {
            $this->name = $data['name'];
        }

        if (isset($data['jobPosition']) && ($this->jobPosition != $data['jobPosition'])) {
            $this->jobPosition = $data['jobPosition'];
        }

        if (isset($data['numberLosses']) && ($this->numberLosses != $data['numberLosses'])) {
            $this->numberLosses = $data['numberLosses'];
        } else if ($this->numberLosses == null) {
            $this->numberLosses = 0;
        }

        if (isset($data['numberWinners']) && ($this->numberWinners != $data['numberWinners'])) {
            $this->numberWinners = $data['numberWinners'];
        } else if ($this->numberWinners == null) {
            $this->numberWinners = 0;
        }

        if (isset($data['obtainedPoints']) && ($this->obtainedPoints != $data['obtainedPoints'])) {
            $this->obtainedPoints = $data['obtainedPoints'];
        } else if ($this->obtainedPoints == null) {
            $this->obtainedPoints = 0;
        }

        if (isset($data['madePoints']) && ($this->madePoints != $data['madePoints'])) {
            $this->madePoints = $data['madePoints'];
        } else if ($this->madePoints == null) {
            $this->madePoints = 0;
        }

        if (isset($data['pathToPicture']) && ($this->pathToPicture != $data['pathToPicture'])){
            $this->pathToPicture = $data['pathToPicture'];
        }

        return $this;
    }

}